From 5c0704bc6fd3c938387f520f175674461bc0eceb Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Fri, 7 May 2010 09:26:49 +0100 Subject: [PATCH] libxl: support vncpassword in device-model specification From: Gihan Munasinghe Signed-off-by: Keir Fraser --- tools/libxl/libxl.c | 32 +++++++++++++++++++++++++++++++- tools/libxl/libxl.h | 2 ++ tools/libxl/xl_cmdimpl.c | 4 ++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index a660ab904b..6d9f011b88 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -769,7 +769,12 @@ static char ** libxl_build_device_model_args(struct libxl_ctx *ctx, flexarray_set(dm_args, num++, "-vnc"); if (info->vncdisplay) { if (info->vnclisten && strchr(info->vnclisten, ':') == NULL) { - flexarray_set(dm_args, num++, libxl_sprintf(ctx, "%s:%d", info->vnclisten, info->vncdisplay)); + flexarray_set( + dm_args, num++, + libxl_sprintf(ctx, "%s:%d%s", + info->vnclisten, + info->vncdisplay, + info->vncpasswd ? ",password" : "")); } else { flexarray_set(dm_args, num++, libxl_sprintf(ctx, "127.0.0.1:%d", info->vncdisplay)); } @@ -892,6 +897,7 @@ static int libxl_vfb_and_vkb_from_device_model_info(struct libxl_ctx *ctx, vfb->vnclisten = info->vnclisten; vfb->vncdisplay = info->vncdisplay; vfb->vncunused = info->vncunused; + vfb->vncpasswd = info->vncpasswd; vfb->keymap = info->keymap; vfb->sdl = info->sdl; vfb->opengl = info->opengl; @@ -1082,6 +1088,9 @@ int libxl_create_device_model(struct libxl_ctx *ctx, int rc; char **args; struct libxl_device_model_starting buf_starting, *p; + xs_transaction_t t; + char *vm_path; + char **pass_stuff; if (strstr(info->device_model, "stubdom-dm")) { libxl_device_vfb vfb; @@ -1118,6 +1127,23 @@ int libxl_create_device_model(struct libxl_ctx *ctx, p->dom_path = libxl_xs_get_dompath(ctx, info->domid); if (!p->dom_path) { libxl_free(ctx, p); return ERROR_FAIL; } + if (info->vncpasswd) { + retry_transaction: + /* Find uuid and the write the vnc password to xenstore for qemu. */ + t = xs_transaction_start(ctx->xsh); + vm_path = libxl_xs_read(ctx,t,libxl_sprintf(ctx, "%s/vm", p->dom_path)); + if (vm_path) { + /* Now write the vncpassword into it. */ + pass_stuff = libxl_calloc(ctx, 2, sizeof(char *)); + pass_stuff[0] = "vncpasswd"; + pass_stuff[1] = info->vncpasswd; + libxl_xs_writev(ctx,t,vm_path,pass_stuff); + if (!xs_transaction_end(ctx->xsh, t, 0)) + if (errno == EAGAIN) + goto retry_transaction; + } + } + rc = libxl_spawn_spawn(ctx, p, "device model", dm_xenstore_record_pid); if (rc < 0) goto xit; if (!rc) { /* inner child */ @@ -1672,6 +1698,8 @@ static int libxl_build_xenpv_qemu_args(struct libxl_ctx *ctx, info->vnclisten = libxl_sprintf(ctx, "%s", vfb->vnclisten); info->vncdisplay = vfb->vncdisplay; info->vncunused = vfb->vncunused; + if (vfb->vncpasswd) + info->vncpasswd = vfb->vncpasswd; if (vfb->keymap) info->keymap = libxl_sprintf(ctx, "%s", vfb->keymap); info->sdl = vfb->sdl; @@ -1753,6 +1781,8 @@ int libxl_device_vfb_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_vfb flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", vfb->vnc)); flexarray_set(back, boffset++, "vnclisten"); flexarray_set(back, boffset++, vfb->vnclisten); + flexarray_set(back, boffset++, "vncpasswd"); + flexarray_set(back, boffset++, vfb->vncpasswd); flexarray_set(back, boffset++, "vncdisplay"); flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", vfb->vncdisplay)); flexarray_set(back, boffset++, "vncunused"); diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 41c4362d40..4f5c493f07 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -148,6 +148,7 @@ typedef struct { bool stdvga; /* stdvga enabled or disabled */ bool vnc; /* vnc enabled or disabled */ char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */ + char *vncpasswd; /* the VNC password */ int vncdisplay; /* set VNC display number */ bool vncunused; /* try to find an unused port for the VNC server */ char *keymap; /* set keyboard layout, default is en-us keyboard */ @@ -169,6 +170,7 @@ typedef struct { int devid; bool vnc; /* vnc enabled or disabled */ char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */ + char *vncpasswd; /* the VNC password */ int vncdisplay; /* set VNC display number */ bool vncunused; /* try to find an unused port for the VNC server */ char *keymap; /* set keyboard layout, default is en-us keyboard */ diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 18f4b5fc40..6fc5e1ebbf 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -627,6 +627,8 @@ skip: (*vfbs)[*num_vfbs].vnc = atoi(p2 + 1); } else if (!strcmp(p, "vnclisten")) { (*vfbs)[*num_vfbs].vnclisten = strdup(p2 + 1); + } else if (!strcmp(p, "vncpasswd")) { + (*vfbs)[*num_vfbs].vncpasswd = strdup(p2 + 1); } else if (!strcmp(p, "vncdisplay")) { (*vfbs)[*num_vfbs].vncdisplay = atoi(p2 + 1); } else if (!strcmp(p, "vncunused")) { @@ -705,6 +707,8 @@ skip_pci: dm_info->vnc = l; if (!xlu_cfg_get_string (config, "vnclisten", &buf)) dm_info->vnclisten = strdup(buf); + if (!xlu_cfg_get_string (config, "vncpasswd", &buf)) + dm_info->vncpasswd = strdup(buf); if (!xlu_cfg_get_long (config, "vncdisplay", &l)) dm_info->vncdisplay = l; if (!xlu_cfg_get_long (config, "vncunused", &l)) -- 2.30.2